package com.ruoyi.modules.controller;

import java.util.Arrays;
import java.util.List;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.ruoyi.modules.domain.AgentLevel;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.modules.domain.TopUpRule;
import com.ruoyi.modules.service.ITopUpRuleService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 充值规则Controller
 *
 * @author ruoyi
 * @date 2022-02-04
 */
@Api(tags = "后台接口 - 充值规则")
@RestController
@RequestMapping("/backstage/topUpRule")
public class TopUpRuleController extends BaseController {
    @Autowired
    private ITopUpRuleService topUpRuleService;

    /**
     * 查询充值规则列表
     */
    @PreAuthorize("@ss.hasPermi('modules:rule:list')")
    @ApiOperation(value="充值规则列表", notes="充值规则列表")
    @GetMapping("/list")
    public TableDataInfo list(TopUpRule topUpRule) {
        startPage();
        List<TopUpRule> list = topUpRuleService.list(new LambdaQueryWrapper<TopUpRule>().orderByAsc(TopUpRule::getNum));
        return getDataTable(list);
    }

    /**
     * 导出充值规则列表
     */
    @PreAuthorize("@ss.hasPermi('modules:rule:export')")
    @Log(title = "充值规则", businessType = BusinessType.EXPORT)
    @ApiOperation(value="导出表格", notes="导出表格")
    @GetMapping("/export")
    public AjaxResult export(TopUpRule topUpRule) {
        List<TopUpRule> list = topUpRuleService.list(new QueryWrapper<>(topUpRule));
        ExcelUtil<TopUpRule> util = new ExcelUtil<TopUpRule>(TopUpRule.class);
        return util.exportExcel(list, "充值规则数据");
    }

    /**
     * 获取充值规则详细信息
     */
    @PreAuthorize("@ss.hasPermi('modules:rule:query')")
    @ApiOperation(value="充值规则详情", notes="充值规则列情")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(topUpRuleService.getById(id));
    }

    /**
     * 新增充值规则
     */
    @PreAuthorize("@ss.hasPermi('modules:rule:add')")
    @Log(title = "充值规则", businessType = BusinessType.INSERT)
    @ApiOperation(value="充值规则新增", notes="充值规则新增")
    @PostMapping
    public AjaxResult add(@RequestBody TopUpRule topUpRule) {
        return toAjax(topUpRuleService.save(topUpRule));
    }

    /**
     * 修改充值规则
     */
    @PreAuthorize("@ss.hasPermi('modules:rule:edit')")
    @Log(title = "充值规则", businessType = BusinessType.UPDATE)
    @ApiOperation(value="充值规则修改", notes="充值规则修改")
    @PutMapping
    public AjaxResult edit(@RequestBody TopUpRule topUpRule) {
        return toAjax(topUpRuleService.updateById(topUpRule));
    }

    /**
     * 删除充值规则
     */
    @PreAuthorize("@ss.hasPermi('modules:rule:remove')")
    @Log(title = "充值规则", businessType = BusinessType.DELETE)
    @ApiOperation(value="充值规则删除", notes="充值规则删除")
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(topUpRuleService.removeByIds(Arrays.asList(ids)));
    }

}
